<?php
class ContactPeopleController extends AppController {

	var $name = 'ContactPeople';

	function beforeFilter(){
		if($this->Session->read('Auth.User')){
			$this->Auth->allow('*');
		}
	}
	
	function admin_index($id = NULL, $model = NULL) {
		if($id != NULL){
			$this->data['ContactPerson']['job_provider_id'] = $id;
			$this->set('id',$id);
		}else if($id != NULL && $model != NULL){
			$this->data['ContactPerson']['id'] = $id;
			$this->set('id',$id);
		}
		if($this->RequestHandler->isAjax()){
			$this->autoRender = false;
			$this->render('row');
			
		}else{
			$contactPeople = $this->ContactPerson->find('all', array('conditions' => array(
																		'ContactPerson.job_provider_id' => $id)));
			$this->set(compact('contactPeople'));
		}
	}

	function admin_save(){
		$this->autoRender = false;
		if (!empty($this->data)) {
			$date = time();
			$this->data['JobLocation']['modified_date'] = strftime("%y-%m-%d",$date);
			$this->ContactPerson->create();
			if ($this->ContactPerson->save($this->data)) {
				$locations = $this->ContactPerson->find('first', array(
														'conditions' => array('ContactPerson.id' => $this->ContactPerson->id)));
				$this->set('location',$locations);
			}else{
				$this->redirect(array('action' => 'index'));
			}
		}
		$this->Render('row');
	}

	function admin_add($id = NULL, $model = NULL) {
		if($id != NULL && $model != NULL){
			$this->data['ContactPerson']['id'] = $id;
			$this->set('id',$id);
		}else if($id != NULL){
			$this->data['ContactPerson']['job_provider_id'] = $id;
			$this->set('id',$id);
		}
		if($this->RequestHandler->isAjax()){
			$this->data = $this->ContactPerson->read(null, $id);
		}else{
			$contactPeople = $this->ContactPerson->find('all', array('conditions' => array(
																		'ContactPerson.job_provider_id' => $id)));
			$this->set(compact('contactPeople'));
		}
	}

	function admin_delete($id = null) {
		if(($this->RequestHandler->isAjax())) {
			$this->autoRender = false;
			if (!$id) {
				return 'error';
			}
			if ($this->ContactPerson->delete($id)) {
				return 'Success';
			}
			return 'error';
		}
	}
}
?>